package dnl.persistence;

public class ColumnInfo {
	private static final int DEFAULT_SIZE = 255;
	private String columnName;
	private SqlType sqlType;
	private int ordinal = -1;
	private int size = -1;

	public ColumnInfo() {

	}

	public ColumnInfo(String columnName, SqlType sqlType) {
		this.columnName = columnName;
		this.sqlType = sqlType;
		switch (sqlType) {
		case VARCHAR:
		case LONGNVARCHAR:
			size = DEFAULT_SIZE;
		default:
			break;
		}
	}

	public ColumnInfo(String columnName, SqlType sqlType, int ordinal) {
		this(columnName, sqlType);
		this.ordinal = ordinal;
	}

	public String getColumnName() {
		return columnName;
	}

	public void setColumnName(String columnName) {
		this.columnName = columnName;
	}

	public SqlType getSqlType() {
		return sqlType;
	}

	public void setSqlType(SqlType sqlType) {
		this.sqlType = sqlType;
	}

	public int getOrdinal() {
		return ordinal;
	}

	public void setOrdinal(int ordinal) {
		this.ordinal = ordinal;
	}

	public int getSize() {
		return size;
	}

	public void setSize(int size) {
		this.size = size;
	}

	public boolean hasSize() {
		return size > 0;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((columnName == null) ? 0 : columnName.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		ColumnInfo other = (ColumnInfo) obj;
		if (columnName == null) {
			if (other.columnName != null)
				return false;
		} else if (!columnName.equals(other.columnName))
			return false;
		return true;
	}

	@Override
	public String toString() {
		return "ColumnInfo [columnName=" + columnName + "]";
	}

}
